import { LibraryRecord } from "../../../../core/library";
import { CSMemberType, Serialize, SerializeClass } from "../../../../core/serialize";
import { Subject } from "../../../../core/subject";
import { UniqueObject, UniqueObjectConfig } from "../../../../core/unique_class";


@SerializeClass("KarmaConfig")
export class KarmaConfig extends UniqueObjectConfig {
    @Serialize()
    name = "";
    @Serialize()
    desc = "";
    @Serialize(Array, CSMemberType.Array)
    funcs: string[] = [];
};

@SerializeClass("Karma")
export class Karma extends UniqueObject<KarmaConfig> {
    static SetValue<T>(obj: T, key: keyof T, val, def) {
        if (val === undefined) {
            obj[key] = def;
        }
        else {
            obj[key] = val;
        }
    }
    static TryParseJson(str: any) {
        try {
            if (typeof str == "string") {
                return JSON.parse(str);
            }
            else {
                return str;
            }
        }
        catch (e) {
            return undefined;
        }
    }
    static CompareValue(v1, v2, type, def) {
        var b = def;
        switch (type) {
            case "==":
                b = (v1 == v2);
                break;
            case "!=":
                b = (v1 != v2);
                break;
            case ">":
                b = (v1 > v2);
                break;
            case "<":
                b = (v1 < v2);
                break;
            case ">=":
            case "=>":
                b = (v1 >= v2);
                break;
            case "<=":
            case "=<":
                b = (v1 <= v2);
                break;
        }
        return b;
    }
};